﻿/// <reference path="jquery.min.js" />
/// <reference path="validated.min.js" />
/// <reference path="md5.min.js" />
/// <reference path="controller.js" />
/// <reference path="webviewadapter.min.js" />

Validated.prototype.onerror = function (key, msg) {
    JsAdapter.ToastShow(msg).Submit();
}

//规则集
var ruleitems = {
    "account": {
        "data": /^\w{6,}$/,
        "normal": "",
        "error": "请输入正确的帐号",
        "required": true
    },
    "pwd": {
        "data": /^.{6,}/,
        "normal": "请输入密码",
        "error": "密码至少6位",
        "required": true
    },
    "nickname": {
        "data": /^[\u4e00-\u9fa5\w]{1,10}/,
        "normal": "请输入昵称",
        "error": "请输入昵称，中文、数字或字母，1~10个字符",
        "required": true
    },
    "realname": {
        "data": /^[\u4e00-\u9fa5\w]{1,10}/,
        "normal": "请输入名称",
        "error": "请输入名称，中文、数字或字母，1~10个字符",
        "required": true
    },
    "avatar": {
        "data": /jpg$/,
        "normal": "请上传头像",
        "error": "请上传头像",
        "required": true
    },
    "birthday": {
        "data": Validated.daterule,
        "normal": "请选择出生日期",
        "error": "请选择出生日期",
        "required": true
    },
    "varietyname": {
        "data": /^.+$/,
        "normal": "请选择类型",
        "error": "请选择类型",
        "required": true
    },
    "smscode": {
        "data": /^\d{6}$/,
        "normal": "请输入验证码",
        "error": "请输入验证码",
        "required": true
    },
    "title": {
        "data": /^[^\s]{2,20}$/,
        "normal": "请输入标题",
        "error": "标题2~20字符",
        "required": true
    },
    "matter": {
        "data": /^.{5,}$/,
        "normal": "请输入内容",
        "error": "内容至少5个字符",
        "required": true
    }
}


//登录验证
var loginvalidate = new Validated();
loginvalidate.rules["loginaccount"] = ruleitems.account;
loginvalidate.rules["loginpwd"] = ruleitems.pwd;


//注册
var regvali = new Validated();
regvali.rules["regaccount"] = ruleitems.account;
regvali.rules["regpwd"] = ruleitems.pwd;
regvali.rules["regsmscode"] = ruleitems.smscode;
regvali.rules["realname"] = ruleitems.realname;
regvali.rules.regsmscode.data = function () {
    return MD5(regvali.rules.regsmscode.value) == RssApp["SmsCode"];
}
regvali.rules["regnickname"] = ruleitems.nickname;
regvali.initdef(true);

//修改密码
var repwd = new Validated();
repwd.rules["oldpwd"] = ruleitems.pwd;
repwd.rules["newpwd"] = ruleitems.pwd;
repwd.rules["renewpwd"] = ruleitems.pwd;
repwd.rules.renewpwd = {
    "data": function () {
        return repwd.rules["newpwd"].value == $("#renewpwd").val();
    },
    "normal": "两次输入的密码不相同",
    "error": "两次输入的密码不相同",
    "required": true
}